﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DTO;
using DAO;

namespace QLDaiLy
{
    public partial class DanhSachDaiLyCanXoa : XtraUserControl
    {
        public DanhSachDaiLyCanXoa()
        {
            InitializeComponent();
        }
    
        private void DanhSachDaiLyCanXoa_Load(object sender, EventArgs e)
        {
            LoadDanhDanhSachDaiLyCanXoa();
           // LoadDanhDanhSachDaiLyCanXoa2();
        }
        private void LoadDanhDanhSachDaiLyCanXoa()
        {

            int tinhtrang = 1;
            List<DaiLyDTO> list = new List<DaiLyDTO>();
            list = DaiLyDAO.LoadDanhSachDaiLyCanXoa(tinhtrang);
            gridDaiLyControl.DataSource = list;
        }

        private void repositoryItemPictureDelete_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Bạn muốn xoá hay không ?", "Thông báo", MessageBoxButtons.OKCancel);
            string MaDaiLy = gridViewDanhSachDaiLy.GetRowCellValue(gridViewDanhSachDaiLy.FocusedRowHandle, gridViewDanhSachDaiLy.Columns["MaDaiLy"]).ToString();
            if (DaiLyDAO.deleteDaiLy(MaDaiLy))
            {
                // MessageBox.Show("Xoá thành công");
                LoadDanhDanhSachDaiLyCanXoa();
            }
            else
            {
                MessageBox.Show("Xoá thành thất bại");
            }
        }

        private void repositoryItemHuyXoa_Click(object sender, EventArgs e)
        {
            string maDaiLy = gridViewDanhSachDaiLy.GetRowCellValue(gridViewDanhSachDaiLy.FocusedRowHandle, gridViewDanhSachDaiLy.Columns["MaDaiLy"]).ToString();
            bool kq =DaiLyDAO.HuyXoaGia(maDaiLy);
            if ( kq== true)
            {
                MessageBox.Show("Cập nhật thành công !");
                // dataGridView.Rows.Add();
                LoadDanhDanhSachDaiLyCanXoa();
            }
            else
            {
                MessageBox.Show("Có lổi khi cập nhật đại lý");
            }
        }

        private void gridViewDanhSachDaiLy_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
        {
            if (e.IsGetData)
            {
                e.Value = QLDaiLy.Properties.Resources.ThemIcon;
            }

            if (e.Column.Caption == "Delete")
            {
                e.Value = QLDaiLy.Properties.Resources.delete;
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}
